﻿<?php
	header("Content-Type:text/html;charset=UTF-8");
	require_once 'config.php';
?>	
<html>
<head>
<title>获取订单列表</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src=js/colors.js></script>
</head>
<body>
<p>此DEMO的功能:获取订单列表</p>
<p id="msgs" style="height:24px;">
<?php
	$ref =$_SERVER['SCRIPT_NAME'];
	if(empty($sessions)){
		echo 'SESSION状态：异常<a href="'.$sessionurl.$appKey.'&ref='.$ref.'">获取Session</a>';exit;
	}else{
		echo 'SESSION状态：正常 <a href="login.php?ac=logout&ref='.$ref.'">退出登陆</a>';
	}
?>
</b>

<?php
	/* Build By fhalipay */
	
/* 获取订单列表 Start*/

	//参数数组
	$paramArr = array(

		/* API系统级输入参数 Start */

	    	'method' => 'taobao.trades.sold.get',  //API名称
		   'session' => $sessions, //session
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

	    	'fields' =>  'seller_nick,buyer_nick,title,type,refund_status,created,iid,price,pic_path,num,tid,buyer_message,sid,shipping_type,alipay_no,payment,discount_fee,adjust_fee,snapshot_url,status,seller_rate,buyer_rate,buyer_memo,seller_memo,pay_time,end_time,modified,buyer_obtain_point_fee,point_fee,real_point_fee,total_fee,post_fee,buyer_alipay_no,receiver_name,receiver_state,receiver_city,receiver_district,receiver_address,receiver_zip,receiver_mobile,receiver_phone,consign_time,buyer_email,commission_fee,seller_alipay_no,seller_mobile,seller_phone,seller_name,seller_email,available_confirm_fee,has_postFee,received_payment,cod_fee,timeout_action_time,orders,sku_id,sku_properties_name,item_meal_name,outer_iid,outer_sku_id',  //返回字段
	 'start_created' => $start_created,  //查询交易创建时间开始
	   'end_created' => $end_created, //查询交易创建时间结束
			'status' => $status, //交易状态
	 	'buyer_nick' => $buyer_nick, //买家淘宝昵称
		      'type' => $type, //交易类型列表
	   'rate_status' => $rate_status, //评价状态
			   'tag' => $tag, //卖家对交易的自定义分组标签，目前可选值为：time_card（点卡软件代充），fee_card（话费软件代充） 
	   	   'page_no' => $page_no, //页码
		  'page_size'=> $page_size, //每页条数。取值范围:大于零的整数; 默认值:40;最大值:100 
 		    'session'=> $sessions
				
		/* API应用级输入参数 End*/
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;
	
	//连接超时自动重试
	$cnt=0;	
	while($cnt < 3 && ($result=@vita_get_url_content($urls))===FALSE) $cnt++;

	//解析Xml数据
	$result = getXmlData($result);

	//获取错误信息
	$msg = $result['msg'];
	
	//返回结果
	$Trade = $result['trades']['trade'];
	$total_results = $result['total_results'];

/* 获取订单列表 End*/	

?>

<form action="" method="get" name="form1" id="form1">
<table border="0" width="100%" class="table">
  <tr>
    <td>状态</td>
    <td>
	<select name="status">
    <option value="">选择</option>    

    <option value="WAIT_BUYER_PAY">(等待买家付款) </option>
    <option value="WAIT_SELLER_SEND_GOODS">(等待卖家发货,即:买家已付款) </option>
    <option value="WAIT_BUYER_CONFIRM_GOODS">(等待买家确认收货,即:卖家已发货) </option>
    <option value="TRADE_BUYER_SIGNED">(买家已签收,货到付款专用) </option>
    <option value="TRADE_FINISHED">(交易成功) </option>
    <option value="TRADE_CLOSED">(交易关闭) </option>
    <option value="TRADE_CLOSED_BY_TAOBAO">(交易被淘宝关闭) </option>

    </select>	
    </td>  
    <td>交易创建时间开始</td>
    <td><input type="text" name="start_created" id="start_created" value="<?php echo (date('Y')-1).'-'.date('m-d H:i:s')?>"></td>
    <td>交易创建时间结束</td>
    <td><input type="text" name="end_created" id="end_created" value="<?php echo date('Y-m-d H:i:s')?>"></td>
    <td>买家昵称</td>    
    <td><input type="text" name="buyer_nick" id="buyer_nick"></td>
  </tr>  
  <tr bgcolor="#dddddd">
    <td>交易类型</td>
    <td>
	<select name="type"> 
    <option value="">选择</option>       
    <option value="fixed">(一口价)</option>
    <option value="auction">(拍卖)</option>
    <option value="guarantee_trade">(一口价、拍卖)</option>
    <option value="auto_delivery">(自动发货)</option>
    <option value="independent_simple_trade">(旺店入门版交易)</option>
    <option value="independent_shop_trade">(旺店标准版交易)</option>
    <option value="ec">(直冲)</option>
    <option value="cod">(货到付款)</option>
    <option value="fenxiao">(分销)</option>
    <option value="game_equipment">(游戏装备)</option>
    <option value="shopex_trade">(ShopEX交易)</option>
    <option value="netcn_trade">(万网交易)</option>
    <option value="external_trade">(统一外部交易)</option>   
	</select>
    </td>
    <td>评价状态</td>
    <td>
	<select name="rate_status">   
    <option value="">选择</option>       
    <option value="RATE_UNBUYER">(买家未评)</option>
    <option value="RATE_UNSELLER">(卖家未评)</option>
    <option value="RATE_BUYER_UNSELLER">(买家已评，卖家未评)</option>
    <option value="RATE_UNBUYER_SELLER">(买家未评，卖家已评)</option>
    </select>
    </td>
    <td>自定义分组标签</td>
  
     
    <td>
	<select name="tag">  
    <option value="">选择</option>
    <option value="time_card">(点卡软件代充)</option>
    <option value="fee_card">(话费软件代充)</option>
    </select>  
    </td>
    <td></td>
    <td>
    <input type="submit" value="搜索订单" >
    </td>
  </tr>
</table>
</form>
<table border="0" width="100%" class="table">

  <tr bgcolor="#FFFFFF">
  	<td>订单号</td>
  	<td>买家</td>   
  	<td>商品名称</td>  
    <td>交易类型</td>     
    <td>订单状态</td> 
    <td>评价状态</td>
    <td>买家地址</td>
    <td>入库</td>
    <td>操作</td>        
  </tr>

	<?php 
	include("include/global.php");
    if(!empty($msg)){
    //错误信息
   	echo '<tr><td colspan=10>错误信息:'.$msg.'</td></tr>';
    }else{
    //处理正确返回信息	
	if ($total_results=='0'){
	echo '<tr><td>没有合乎条件的数据</td></tr>';	
	}else if($total_results=='1'){	
	?>
  <tr>  
    <td><?php echo $Trade['tid'];?></td>
    <td><?php echo $Trade['buyer_nick'];?></td>    
    <td><?php echo $Trade['title'];?></td> 
    <td><?php echo getTypes($Trade['type']);?></td>    
    <td><?php echo getStatus($Trade['status']);?></td>         
    <td><?php echo getRate($Trade['seller_rate'],$Trade['buyer_rate']);?></td>
    <td><?php echo $Trade['receiver_address'];?></td>    
	<td>
    <?php
		$tid=$Trade['tid'];
		$title=$Trade['title'];	
		$status=$Trade['status'];			
		$addtime=time();
		$rs=$db->query("select * from `".PRE."order` where tid='".$tid."'");
		if(is_array($row=$db->fetch_array($rs))){
			echo '<font color=green>已入库</font>';
		}else{
		$sql1="insert into `".PRE."order` (`tid`,`title`,`status`,`addtime`) values('".$tid."','".$title."','".$status."','".$addtime."')";
		echo '<font color=red>成功入库</font>';
		$db->query($sql1) or die("入库失败".mysql_error());
		}

    ?>    
    </td>   
	<td>
    <?php
	if ($Trade['status']=='WAIT_SELLER_SEND_GOODS'){
    echo '<a href="taobao.delivery.send.php?tid='.$Trade['tid'].'" target="_blank">发货</a>';
	}else{
	echo '<font color="#dddddd">已发货</font>';
	}
	?>    
    </td>     
  </tr>     
    <?php
	}else{
	foreach ($Trade as $key => $val){
	?>

  <tr bgcolor="#FFFFFF">  
    <td><?php echo $val['tid'];?></td>
    <td><?php echo $val['buyer_nick'];?></td>    
    <td><?php echo $val['title'];?></td> 
    <td><?php echo getTypes($val['type']);?></td>        
    <td><?php echo getStatus($val['status']);?></td>         
    <td><?php echo getRate($val['seller_rate'],$val['buyer_rate']);?></td>
    <td><?php echo $val['receiver_address'];?></td>
	<td>
    <?php
		$tid=$val['tid'];
		$title=$val['title'];		
		$status=$val['status'];
		$addtime=time();
		$rs=$db->query("select * from `".PRE."order` where tid='".$tid."'");
		if(is_array($row=$db->fetch_array($rs))){
			echo '<font color=green>已入库</font>';
		}else{
		$sql1="insert into `".PRE."order` (`tid`,`title`,`status`,`addtime`) values('".$tid."','".$title."','".$status."','".$addtime."')";
		echo '<font color=red>成功入库</font>';
		$db->query($sql1) or die("入库失败".mysql_error());
		}

    ?>
    </td>
    <td>
    <?php
	if ($val['status']=='WAIT_SELLER_SEND_GOODS'){
    echo '<a href="taobao.delivery.send.php?tid='.$val['tid'].'" target="_blank">发货</a>';
	}else{
	echo '<font color="#999999">已发货</font>';
	}
	?>
    </td>    
    
           
  </tr> 
   <?php }?>
    <tr>
      <td colspan="15"> 
	 <?php
	// 分页 new PageClass(数据总数,每页数量,页码,URL组成);
	$pages = new PageClass($total_results,$page_size,$_GET['page'],'?'.$_SERVER['QUERY_STRING'].'&page={page}');
	echo $pages -> myde_write();
	?>
      </td>
    </tr>    
   <?php

	}
	?>  
  <tr>
    <td align="right" colspan="9">
    	 <a href="clearDB.php?ac=yes" target="_blank">清除表中数据测试</a><br>
    	 <a href="list.php" target="_blank">显示入库信息</a><br>         

    </td>
  </tr>   
</table>
<?php
}?>
<p>请支持我们的网站：<a href="http://www.uscms.cn/">淘宝导购网</a> <a href="http://www.yeyoubao.com/tools">淘宝客工具</a></p>
</body>
</html>
